﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "GbmpModel.h"
#include "IElementParametersCustomizer.h"
#include "DbDataSchema.h"
#include "DbObjectUtils.h"
#include "IParameterDefinitionLibrary.h"
#include "IParameterOverride.h"
#include "GcmpBuiltInParameterDefinitions.h"
#include "UniIdentity.h"

namespace gcmp
{
    class IDrawingLayout;
    class IDrawingViewport;
    class IModelView;
    class GBMP_MODEL_EXPORT GbmpElementParametersCustomizer : public NdbObjectSchematic, public IElementParametersCustomizer
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, GbmpElementParametersCustomizer, gcmp::NdbObjectSchematic, D1442E2A - B664 - 4C85 - BD79 - CF17A4C692EB, gbmpmodel, IElementParametersCustomizer)
        DBOBJECT_DATA_END
    public:
        virtual bool SetOwnerElement(IElement* pOwnerElement) override { return true; };
        virtual IElement* GetOwnerElement() override { return nullptr; }
        virtual const IElement* GetOwnerElement() const override { return nullptr; }

        virtual OwnerPtr<IParameter> GetNativeParameter(int parameterId) const override {
            return nullptr;
        };

        virtual bool SetNativeParameter(const IParameter* pParameter, std::wstring* errorMessage = nullptr) {
            return true;
        };

        virtual void ReportParameterDefinitions(std::vector<int>* parameterIds) const {};

        virtual bool IsParameterModifiable(int parameterId) const {
            return true;
        };

        virtual bool IsPresetParameter(const UniIdentity& parameterDefinitionUid) const {
            return true;
        };

        virtual void FilterParameterValues(const UniIdentity& parameterDefinitionUid,
            std::vector<OwnerPtr<IParameterValueStorage>>& values) const { };

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override
        {
            return nullptr;
        }
    };

    class GBMP_MODEL_EXPORT LayoutParametersCustomizer : public GbmpElementParametersCustomizer
    {
        DBOBJECT_DATA_BEGIN(gcmp, LayoutParametersCustomizer, gcmp::GbmpElementParametersCustomizer, 3B3B2B17 - 97E0 - 46B5 - B1FF - CD5A4BEC73B0, gbmpmodel)
        DATA_TRANSIENT(IElement*, pOwnerElement)
        DBOBJECT_DATA_END
    public:
        LayoutParametersCustomizer(IElement* pOwnerElement)
            : m_pOwnerElement(pOwnerElement)
        {
        }

        virtual bool SetOwnerElement(IElement* pOwnerElement) override { m_pOwnerElement = pOwnerElement; return true; };
        virtual IElement* GetOwnerElement() override { return m_pOwnerElement; }
        virtual const IElement* GetOwnerElement() const override { return m_pOwnerElement; }
        virtual OwnerPtr<IParameter> GetNativeParameter(int paramDefId) const override;
        virtual bool SetNativeParameter(const IParameter *param, std::wstring* errorMsg) override;
        virtual void ReportParameterDefinitions(std::vector<int>* pParamDefIds) const override;
        virtual bool IsParameterModifiable(int parameterId) const override;
        virtual bool IsPresetParameter(const UniIdentity& paramDefUid) const override { return true; }
        virtual void FilterParameterValues(const UniIdentity& paramDefUid,
            std::vector<OwnerPtr<IParameterValueStorage>>& values) const override {}

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override
        {
            return nullptr;
        }
    protected:
        IDocument* GetDocument() const;
    private:
        const IDrawingLayout* GetLayout() const;
        IDrawingLayout* GetLayout();
        const IModelView* GetModelView(const IDrawingViewport* pViewport) const;
    };

    class IDrawingViewport;
    class GBMP_MODEL_EXPORT ViewPortParametersCustomizer : public GbmpElementParametersCustomizer
    {
        DBOBJECT_DATA_BEGIN(gcmp, ViewPortParametersCustomizer, gcmp::GbmpElementParametersCustomizer, 43CD7C09 - C0BD - 4D5B - B5AB - 275BC04D2230, gbmpmodel)
        DATA_TRANSIENT(IElement*, pOwnerElement)
        DBOBJECT_DATA_END
    public:
        ViewPortParametersCustomizer(IElement* pElement);
        virtual ~ViewPortParametersCustomizer();
        virtual bool SetOwnerElement(IElement* pOwnerElement) override { m_pOwnerElement = pOwnerElement; return true; };
        virtual IElement* GetOwnerElement() override { return m_pOwnerElement; }
        virtual const IElement* GetOwnerElement() const override { return m_pOwnerElement; }
        virtual OwnerPtr<IParameter> GetNativeParameter(int paramDefId) const override;
        virtual bool SetNativeParameter(const IParameter *param, std::wstring* errorMsg) override;
        virtual void ReportParameterDefinitions(std::vector<int>* pParamDefIds) const override;
        virtual bool IsParameterModifiable(int paramDefId) const override;
        virtual bool IsPresetParameter(const UniIdentity& paramDefUid) const override { return true; }
        virtual void FilterParameterValues(const UniIdentity& paramDefUid,
            std::vector<OwnerPtr<IParameterValueStorage>>& values) const override {}

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override
        {
            return nullptr;
        }
    protected:
        IDocument* GetDocument() const;
    private:
        const IDrawingViewport* GetViewport() const;
        IDrawingViewport* GetViewportFW();
    };
}

namespace gcmp
{
    class GBMP_MODEL_EXPORT ViewportScaleOverride : public NdbObjectSchematic, public IParameterOverride
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, ViewportScaleOverride, gcmp::NdbObjectSchematic, 37BF0916 - 167A - 4D7B - BDE9 - 2346F174978B, gbmpmodel, gcmp::IParameterOverride)
        DBOBJECT_DATA_END
    public:
        virtual UniIdentity GetUniIdentity() const override { return PARAMETER_UID(ViewScaleBuiltInParameter); }
        virtual bool ShouldOverrideIsModifiable() const override { return false; }
        virtual bool IsModifiable() const override { return true; }
        virtual bool ShouldOverrideIsUserVisible() const override { return false; }
        virtual bool IsUserVisible() const override { return true; }
        virtual bool ShouldOverrideGetName() const override { return true; }
        virtual std::wstring GetName() const override { return L"视口比例"; }
        virtual bool ShouldOverrideGetValidator() const override { return false; }
        virtual const IParameterValidator * GetValidator() const override { return nullptr; }

        virtual IElement* GetOwnerElement() override { return nullptr; }
        virtual const IElement* GetOwnerElement() const override { return nullptr; }
        virtual bool SetOwnerElement(IElement* pElement) override { return true; }

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override
        {
            return nullptr;
        }
    };


    class GBMP_MODEL_EXPORT ViewportCropByBorderOverride : public NdbObjectSchematic, public IParameterOverride
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, ViewportCropByBorderOverride, gcmp::NdbObjectSchematic, 8D8D12F3 - A9F1 - 4A82 - B85B - B91023801951, gbmpmodel, gcmp::IParameterOverride)
        DBOBJECT_DATA_END
    public:
        virtual UniIdentity GetUniIdentity() const override { return PARAMETER_UID(ViewCropByBorderBuiltInParameter); }
        virtual bool ShouldOverrideIsModifiable() const override { return false; }
        virtual bool IsModifiable() const override { return true; }
        virtual bool ShouldOverrideIsUserVisible() const override { return false; }
        virtual bool IsUserVisible() const override { return true; }
        virtual bool ShouldOverrideGetName() const override { return true; }
        virtual std::wstring GetName() const override { return L"视图剪裁"; }
        virtual bool ShouldOverrideGetValidator() const override { return false; }
        virtual const IParameterValidator * GetValidator() const override { return nullptr; }

        virtual IElement* GetOwnerElement() override { return nullptr; }
        virtual const IElement* GetOwnerElement() const override { return nullptr; }
        virtual bool SetOwnerElement(IElement* pElement) override { return true; }

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override
        {
            return nullptr;
        }
    };


    class GBMP_MODEL_EXPORT ViewportBorderVisibleOverride : public NdbObjectSchematic, public IParameterOverride
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, ViewportBorderVisibleOverride, gcmp::NdbObjectSchematic, 29988E01 - 6E95 - 4B03 - A37A - 61C1183BB9EC, gbmpmodel, gcmp::IParameterOverride)
        DBOBJECT_DATA_END
    public:
        virtual UniIdentity GetUniIdentity() const override { return PARAMETER_UID(ViewBorderVisibleBuiltInParameter); }
        virtual bool ShouldOverrideIsModifiable() const override { return false; }
        virtual bool IsModifiable() const override { return true; }
        virtual bool ShouldOverrideIsUserVisible() const override { return false; }
        virtual bool IsUserVisible() const override { return true; }
        virtual bool ShouldOverrideGetName() const override { return true; }
        virtual std::wstring GetName() const override { return L"显示剪裁框"; }
        virtual bool ShouldOverrideGetValidator() const override { return false; }
        virtual const IParameterValidator * GetValidator() const override { return nullptr; }

        virtual IElement* GetOwnerElement() override { return nullptr; }
        virtual const IElement* GetOwnerElement() const override { return nullptr; }
        virtual bool SetOwnerElement(IElement* pElement) override { return true; }
    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override
        {
            return nullptr;
        }
    };
}


namespace gcmp
{
    class GBMP_MODEL_EXPORT DrawingViewportTypeParametersCustomizer : public GbmpElementParametersCustomizer
    {
        DBOBJECT_DATA_BEGIN(gcmp, DrawingViewportTypeParametersCustomizer, gcmp::GbmpElementParametersCustomizer, DD1D4114 - 5BF9 - 4A74 - A772 - 4AE28F1E644A, gbmpmodel)
        DATA_TRANSIENT(IElement*, pOwnerElement)
        DBOBJECT_DATA_END

    public:
        DrawingViewportTypeParametersCustomizer(IElement* pOwnerElement)
            : m_pOwnerElement(pOwnerElement)
        {

        }

        virtual bool SetOwnerElement(IElement* pOwnerElement) override { m_pOwnerElement = pOwnerElement; return true; };
        virtual IElement* GetOwnerElement() override { return m_pOwnerElement; }
        virtual const IElement* GetOwnerElement() const override { return m_pOwnerElement; }
        virtual OwnerPtr<IParameter> GetNativeParameter(int paramDefId) const override;
        virtual bool SetNativeParameter(const IParameter *param, std::wstring* errorMsg) override;
        void ReportParameterDefinitions(std::vector<int>* pParamDefIds) const override;
        virtual bool IsParameterModifiable(int parameterId) const override;
        virtual bool IsPresetParameter(const UniIdentity& paramDefUid) const override { return true; }
        virtual void FilterParameterValues(const UniIdentity& paramDefUid,
            std::vector<OwnerPtr<IParameterValueStorage>>& values) const override {}

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override
        {
            return nullptr;
        }
    protected:
        IDocument* GetDocument() const;
    };
}
